//
//  NSString+LHLMD5.m
//  24-HomeWork
//
//  Created by 李昊林 on 16/8/16.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "NSString+LHLMD5.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (LHLMD5)
- (NSString *)StringWith32BitMD5{
    const char *cString = [self UTF8String];
    CC_LONG length = (CC_LONG)strlen(cString);
    unsigned char bytes[CC_MD5_DIGEST_LENGTH];
    CC_MD5(cString, length, bytes);
    NSMutableString *finalMD5String = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++){
        [finalMD5String appendFormat:@"%02x", bytes[i]];
    }
    return finalMD5String;
}
- (NSString *)StringWith32BitMD5Upper{
    const char *cString = [self UTF8String];
    CC_LONG length = (CC_LONG)strlen(cString);
    unsigned char bytes[CC_MD5_DIGEST_LENGTH];
    CC_MD5(cString, length, bytes);
    NSMutableString *finalMD5String = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++){
        [finalMD5String appendFormat:@"%02x", bytes[i]];
    }
    return finalMD5String;
}
- (NSString *)StringWith32BitMD5Lower{
    return [[self StringWith32BitMD5] uppercaseString];

}
- (NSString *)StringWith16BitMd5 {
    NSString *md5String32Bit = [self StringWith32BitMD5];
    NSString *md5String16Bit = [md5String32Bit substringToIndex:md5String32Bit.length - 8];
    md5String16Bit = [md5String16Bit substringFromIndex:8];
    return md5String16Bit;

}
- (NSString *)StringWith16BitMD5Upper{
    return @"";
}
- (NSString *)StringWith16BitMd5Lower{
    return @"";
}

@end
